<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Rails::Generator::Commands::Create</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Rails::Generator::Commands::Create</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/railties/lib/rails_generator/commands_rb.html">
                vendor/rails/railties/lib/rails_generator/commands.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="Base.html">
                Base
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="Create.html">Create</a> is the premier generator command. It
copies files, creates directories, renders templates, and more.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001522">class_collisions</a>&nbsp;&nbsp;
      <a href="#M001526">complex_template</a>&nbsp;&nbsp;
      <a href="#M001527">directory</a>&nbsp;&nbsp;
      <a href="#M001523">file</a>&nbsp;&nbsp;
      <a href="#M001524">identical?</a>&nbsp;&nbsp;
      <a href="#M001529">migration_template</a>&nbsp;&nbsp;
      <a href="#M001528">readme</a>&nbsp;&nbsp;
      <a href="#M001530">route_resources</a>&nbsp;&nbsp;
      <a href="#M001525">template</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">SYNONYM_LOOKUP_URI</td>
          <td>=</td>
          <td class="context-item-value">&quot;http://wordnet.princeton.edu/cgi-bin/webwn2.0?stage=2&amp;word=%s&amp;posnumber=1&amp;searchtypenumber=2&amp;senses=&amp;showglosses=1&quot;</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001522" class="method-detail">
        <a name="M001522"></a>

        <div class="method-heading">
          <a href="#M001522" class="method-signature">
          <span class="method-name">class_collisions</span><span class="method-args">(*class_names)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Check whether the given class names are already taken by Ruby or <a
href="../../../Rails.html">Rails</a>. In the future, expand to check other
namespaces such as the rest of the user&#8216;s app.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001522-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001522-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/commands.rb, line 168</span>
168:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">class_collisions</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">class_names</span>)
169:           <span class="ruby-identifier">class_names</span>.<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">class_name</span><span class="ruby-operator">|</span>
170:             <span class="ruby-comment cmt"># Convert to string to allow symbol arguments.</span>
171:             <span class="ruby-identifier">class_name</span> = <span class="ruby-identifier">class_name</span>.<span class="ruby-identifier">to_s</span>
172: 
173:             <span class="ruby-comment cmt"># Skip empty strings.</span>
174:             <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">class_name</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">empty?</span>
175: 
176:             <span class="ruby-comment cmt"># Split the class from its module nesting.</span>
177:             <span class="ruby-identifier">nesting</span> = <span class="ruby-identifier">class_name</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'::'</span>)
178:             <span class="ruby-identifier">name</span> = <span class="ruby-identifier">nesting</span>.<span class="ruby-identifier">pop</span>
179: 
180:             <span class="ruby-comment cmt"># Extract the last Module in the nesting.</span>
181:             <span class="ruby-identifier">last</span> = <span class="ruby-identifier">nesting</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-constant">Object</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">last</span>, <span class="ruby-identifier">nest</span><span class="ruby-operator">|</span>
182:               <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">last</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-identifier">nest</span>)
183:               <span class="ruby-identifier">last</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">nest</span>)
184:             }
185: 
186:             <span class="ruby-comment cmt"># If the last Module exists, check whether the given</span>
187:             <span class="ruby-comment cmt"># class exists and raise a collision if so.</span>
188:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">last</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">last</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">camelize</span>)
189:               <span class="ruby-identifier">raise_class_collision</span>(<span class="ruby-identifier">class_name</span>)
190:             <span class="ruby-keyword kw">end</span>
191:           <span class="ruby-keyword kw">end</span>
192:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001526" class="method-detail">
        <a name="M001526"></a>

        <div class="method-heading">
          <a href="#M001526" class="method-signature">
          <span class="method-name">complex_template</span><span class="method-args">(relative_source, relative_destination, template_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001526-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001526-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/commands.rb, line 299</span>
299:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">complex_template</span>(<span class="ruby-identifier">relative_source</span>, <span class="ruby-identifier">relative_destination</span>, <span class="ruby-identifier">template_options</span> = {})
300:           <span class="ruby-identifier">options</span> = <span class="ruby-identifier">template_options</span>.<span class="ruby-identifier">dup</span>
301:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:assigns</span>] <span class="ruby-operator">||=</span> {}
302:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:assigns</span>][<span class="ruby-value str">'template_for_inclusion'</span>] = <span class="ruby-identifier">render_template_part</span>(<span class="ruby-identifier">template_options</span>)
303:           <span class="ruby-identifier">template</span>(<span class="ruby-identifier">relative_source</span>, <span class="ruby-identifier">relative_destination</span>, <span class="ruby-identifier">options</span>)
304:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001527" class="method-detail">
        <a name="M001527"></a>

        <div class="method-heading">
          <a href="#M001527" class="method-signature">
          <span class="method-name">directory</span><span class="method-args">(relative_path)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="Create.html">Create</a> a <a
href="Create.html#M001527">directory</a> including any missing parent
directories. Always directories which exist.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001527-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001527-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/commands.rb, line 308</span>
308:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">directory</span>(<span class="ruby-identifier">relative_path</span>)
309:           <span class="ruby-identifier">path</span> = <span class="ruby-identifier">destination_path</span>(<span class="ruby-identifier">relative_path</span>)
310:           <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">path</span>)
311:             <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">exists</span> <span class="ruby-identifier">relative_path</span>
312:           <span class="ruby-keyword kw">else</span>
313:             <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">create</span> <span class="ruby-identifier">relative_path</span>
314:             <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:pretend</span>]
315:               <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">mkdir_p</span>(<span class="ruby-identifier">path</span>)
316:               
317:               <span class="ruby-comment cmt"># Subversion doesn't do path adds, so we need to add</span>
318:               <span class="ruby-comment cmt"># each directory individually.</span>
319:               <span class="ruby-comment cmt"># So stack up the directory tree and add the paths to</span>
320:               <span class="ruby-comment cmt"># subversion in order without recursion.</span>
321:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:svn</span>]
322:                 <span class="ruby-identifier">stack</span>=[<span class="ruby-identifier">relative_path</span>]
323:                 <span class="ruby-keyword kw">until</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">stack</span>.<span class="ruby-identifier">last</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">last</span> <span class="ruby-comment cmt"># dirname('.') == '.'</span>
324:                   <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">push</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">stack</span>.<span class="ruby-identifier">last</span>)
325:                 <span class="ruby-keyword kw">end</span>
326:                 <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">reverse_each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">rel_path</span><span class="ruby-operator">|</span>
327:                   <span class="ruby-identifier">svn_path</span> = <span class="ruby-identifier">destination_path</span>(<span class="ruby-identifier">rel_path</span>)
328:                   <span class="ruby-identifier">system</span>(<span class="ruby-node">&quot;svn add -N #{svn_path}&quot;</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">svn_path</span>, <span class="ruby-value str">'.svn'</span>))
329:                 <span class="ruby-keyword kw">end</span>
330:               <span class="ruby-keyword kw">end</span>
331:             <span class="ruby-keyword kw">end</span>
332:           <span class="ruby-keyword kw">end</span>
333:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001523" class="method-detail">
        <a name="M001523"></a>

        <div class="method-heading">
          <a href="#M001523" class="method-signature">
          <span class="method-name">file</span><span class="method-args">(relative_source, relative_destination, file_options = {}, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Copy a <a href="Create.html#M001523">file</a> from source to destination
with collision checking.
</p>
<p>
The file_options hash accepts :chmod and :shebang and :collision options.
:chmod sets the permissions of the destination <a
href="Create.html#M001523">file</a>:
</p>
<pre>
  file 'config/empty.log', 'log/test.log', :chmod =&gt; 0664
</pre>
<p>
:shebang sets the #!/usr/bin/ruby line for scripts
</p>
<pre>
  file 'bin/generate.rb', 'script/generate', :chmod =&gt; 0755, :shebang =&gt; '/usr/bin/env ruby'
</pre>
<p>
:collision sets the collision option only for the destination <a
href="Create.html#M001523">file</a>:
</p>
<pre>
  file 'settings/server.yml', 'config/server.yml', :collision =&gt; :skip
</pre>
<p>
Collisions are handled by checking whether the destination <a
href="Create.html#M001523">file</a> exists and either skipping the <a
href="Create.html#M001523">file</a>, forcing overwrite, or asking the user
what to do.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001523-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001523-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/commands.rb, line 207</span>
207:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">file</span>(<span class="ruby-identifier">relative_source</span>, <span class="ruby-identifier">relative_destination</span>, <span class="ruby-identifier">file_options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
208:           <span class="ruby-comment cmt"># Determine full paths for source and destination files.</span>
209:           <span class="ruby-identifier">source</span>              = <span class="ruby-identifier">source_path</span>(<span class="ruby-identifier">relative_source</span>)
210:           <span class="ruby-identifier">destination</span>         = <span class="ruby-identifier">destination_path</span>(<span class="ruby-identifier">relative_destination</span>)
211:           <span class="ruby-identifier">destination_exists</span>  = <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">destination</span>)
212: 
213:           <span class="ruby-comment cmt"># If source and destination are identical then we're done.</span>
214:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">destination_exists</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">identical?</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">destination</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
215:             <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">identical</span>(<span class="ruby-identifier">relative_destination</span>) 
216:           <span class="ruby-keyword kw">end</span>
217: 
218:           <span class="ruby-comment cmt"># Check for and resolve file collisions.</span>
219:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">destination_exists</span>
220: 
221:             <span class="ruby-comment cmt"># Make a choice whether to overwrite the file.  :force and</span>
222:             <span class="ruby-comment cmt"># :skip already have their mind made up, but give :ask a shot.</span>
223:             <span class="ruby-identifier">choice</span> = <span class="ruby-keyword kw">case</span> (<span class="ruby-identifier">file_options</span>[<span class="ruby-identifier">:collision</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:collision</span>]).<span class="ruby-identifier">to_sym</span> <span class="ruby-comment cmt">#|| :ask</span>
224:               <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:ask</span>   <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">force_file_collision?</span>(<span class="ruby-identifier">relative_destination</span>, <span class="ruby-identifier">source</span>, <span class="ruby-identifier">destination</span>, <span class="ruby-identifier">file_options</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
225:               <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:force</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">:force</span>
226:               <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:skip</span>  <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">:skip</span>
227:               <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Invalid collision option: #{options[:collision].inspect}&quot;</span>
228:             <span class="ruby-keyword kw">end</span>
229: 
230:             <span class="ruby-comment cmt"># Take action based on our choice.  Bail out if we chose to</span>
231:             <span class="ruby-comment cmt"># skip the file; otherwise, log our transgression and continue.</span>
232:             <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">choice</span>
233:               <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:force</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">force</span>(<span class="ruby-identifier">relative_destination</span>)
234:               <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:skip</span>  <span class="ruby-keyword kw">then</span> <span class="ruby-keyword kw">return</span>(<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">skip</span>(<span class="ruby-identifier">relative_destination</span>))
235:               <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Invalid collision choice: #{choice}.inspect&quot;</span>
236:             <span class="ruby-keyword kw">end</span>
237: 
238:           <span class="ruby-comment cmt"># File doesn't exist so log its unbesmirched creation.</span>
239:           <span class="ruby-keyword kw">else</span>
240:             <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">create</span> <span class="ruby-identifier">relative_destination</span>
241:           <span class="ruby-keyword kw">end</span>
242: 
243:           <span class="ruby-comment cmt"># If we're pretending, back off now.</span>
244:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:pretend</span>]
245: 
246:           <span class="ruby-comment cmt"># Write destination file with optional shebang.  Yield for content</span>
247:           <span class="ruby-comment cmt"># if block given so templaters may render the source file.  If a</span>
248:           <span class="ruby-comment cmt"># shebang is requested, replace the existing shebang or insert a</span>
249:           <span class="ruby-comment cmt"># new one.</span>
250:           <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">destination</span>, <span class="ruby-value str">'wb'</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">dest</span><span class="ruby-operator">|</span>
251:             <span class="ruby-identifier">dest</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">render_file</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">file_options</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
252:           <span class="ruby-keyword kw">end</span>
253: 
254:           <span class="ruby-comment cmt"># Optionally change permissions.</span>
255:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">file_options</span>[<span class="ruby-identifier">:chmod</span>]
256:             <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">chmod</span>(<span class="ruby-identifier">file_options</span>[<span class="ruby-identifier">:chmod</span>], <span class="ruby-identifier">destination</span>)
257:           <span class="ruby-keyword kw">end</span>
258: 
259:           <span class="ruby-comment cmt"># Optionally add file to subversion</span>
260:           <span class="ruby-identifier">system</span>(<span class="ruby-node">&quot;svn add #{destination}&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:svn</span>]
261:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001524" class="method-detail">
        <a name="M001524"></a>

        <div class="method-heading">
          <a href="#M001524" class="method-signature">
          <span class="method-name">identical?</span><span class="method-args">(source, destination) {|sf| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Checks if the source and the destination <a
href="Create.html#M001523">file</a> are identical. If passed a block then
the source <a href="Create.html#M001523">file</a> is a <a
href="Create.html#M001525">template</a> that needs to first be evaluated
before being compared to the destination.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001524-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001524-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/commands.rb, line 266</span>
266:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">identical?</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">destination</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
267:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span> <span class="ruby-identifier">destination</span>
268:           <span class="ruby-identifier">source</span>      = <span class="ruby-identifier">block_given?</span> <span class="ruby-value">? </span><span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">source</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">sf</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">sf</span>)} <span class="ruby-operator">:</span> <span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">source</span>)
269:           <span class="ruby-identifier">destination</span> = <span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">destination</span>)
270:           <span class="ruby-identifier">source</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">destination</span>
271:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001529" class="method-detail">
        <a name="M001529"></a>

        <div class="method-heading">
          <a href="#M001529" class="method-signature">
          <span class="method-name">migration_template</span><span class="method-args">(relative_source, relative_destination, template_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
When creating a migration, it knows to find the first available <a
href="Create.html#M001523">file</a> in db/migrate and use the migration.rb
<a href="Create.html#M001525">template</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001529-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001529-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/commands.rb, line 344</span>
344:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">migration_template</span>(<span class="ruby-identifier">relative_source</span>, <span class="ruby-identifier">relative_destination</span>, <span class="ruby-identifier">template_options</span> = {})
345:           <span class="ruby-identifier">migration_directory</span> <span class="ruby-identifier">relative_destination</span>
346:           <span class="ruby-identifier">migration_file_name</span> = <span class="ruby-identifier">template_options</span>[<span class="ruby-identifier">:migration_file_name</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">file_name</span>
347:           <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">migration_exists?</span>(<span class="ruby-identifier">migration_file_name</span>)
348:           <span class="ruby-identifier">template</span>(<span class="ruby-identifier">relative_source</span>, <span class="ruby-node">&quot;#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb&quot;</span>, <span class="ruby-identifier">template_options</span>)
349:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001528" class="method-detail">
        <a name="M001528"></a>

        <div class="method-heading">
          <a href="#M001528" class="method-signature">
          <span class="method-name">readme</span><span class="method-args">(*relative_sources)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Display a README.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001528-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001528-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/commands.rb, line 336</span>
336:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">readme</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">relative_sources</span>)
337:           <span class="ruby-identifier">relative_sources</span>.<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">relative_source</span><span class="ruby-operator">|</span>
338:             <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">readme</span> <span class="ruby-identifier">relative_source</span>
339:             <span class="ruby-identifier">puts</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">source_path</span>(<span class="ruby-identifier">relative_source</span>)) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:pretend</span>]
340:           <span class="ruby-keyword kw">end</span>
341:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001530" class="method-detail">
        <a name="M001530"></a>

        <div class="method-heading">
          <a href="#M001530" class="method-signature">
          <span class="method-name">route_resources</span><span class="method-args">(*resources)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001530-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001530-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/commands.rb, line 351</span>
351:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">route_resources</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">resources</span>)
352:           <span class="ruby-identifier">resource_list</span> = <span class="ruby-identifier">resources</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">to_sym</span>.<span class="ruby-identifier">inspect</span> }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">', '</span>)
353:           <span class="ruby-identifier">sentinel</span> = <span class="ruby-value str">'ActionController::Routing::Routes.draw do |map|'</span>
354: 
355:           <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">route</span> <span class="ruby-node">&quot;map.resources #{resource_list}&quot;</span>
356:           <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:pretend</span>]
357:             <span class="ruby-identifier">gsub_file</span> <span class="ruby-value str">'config/routes.rb'</span>, <span class="ruby-node">/(#{Regexp.escape(sentinel)})/</span><span class="ruby-identifier">mi</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
358:               <span class="ruby-node">&quot;#{match}\n  map.resources #{resource_list}\n&quot;</span>
359:             <span class="ruby-keyword kw">end</span>
360:           <span class="ruby-keyword kw">end</span>
361:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001525" class="method-detail">
        <a name="M001525"></a>

        <div class="method-heading">
          <a href="#M001525" class="method-signature">
          <span class="method-name">template</span><span class="method-args">(relative_source, relative_destination, template_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Generate a <a href="Create.html#M001523">file</a> for a <a
href="../../../Rails.html">Rails</a> application using an ERuby <a
href="Create.html#M001525">template</a>. Looks up and evaluates a <a
href="Create.html#M001525">template</a> by name and writes the result.
</p>
<p>
The <a href="../../../ERB.html">ERB</a> <a
href="Create.html#M001525">template</a> uses explicit trim mode to best
control the proliferation of whitespace in generated code. &lt;%- trims
leading whitespace; -%&gt; trims trailing whitespace including one newline.
</p>
<p>
A hash of <a href="Create.html#M001525">template</a> options may be passed
as the last argument. The options accepted by the <a
href="Create.html#M001523">file</a> are accepted as well as :assigns, a
hash of variable bindings. Example:
</p>
<pre>
  template 'foo', 'bar', :assigns =&gt; { :action =&gt; 'view' }
</pre>
<p>
Template is implemented in terms of <a href="Create.html#M001523">file</a>.
It calls <a href="Create.html#M001523">file</a> with a block which takes a
<a href="Create.html#M001523">file</a> handle and returns its rendered
contents.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001525-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001525-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/commands.rb, line 287</span>
287:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">template</span>(<span class="ruby-identifier">relative_source</span>, <span class="ruby-identifier">relative_destination</span>, <span class="ruby-identifier">template_options</span> = {})
288:           <span class="ruby-identifier">file</span>(<span class="ruby-identifier">relative_source</span>, <span class="ruby-identifier">relative_destination</span>, <span class="ruby-identifier">template_options</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
289:             <span class="ruby-comment cmt"># Evaluate any assignments in a temporary, throwaway binding.</span>
290:             <span class="ruby-identifier">vars</span> = <span class="ruby-identifier">template_options</span>[<span class="ruby-identifier">:assigns</span>] <span class="ruby-operator">||</span> {}
291:             <span class="ruby-identifier">b</span> = <span class="ruby-identifier">binding</span>
292:             <span class="ruby-identifier">vars</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">eval</span> <span class="ruby-node">&quot;#{k} = vars[:#{k}] || vars['#{k}']&quot;</span>, <span class="ruby-identifier">b</span> }
293: 
294:             <span class="ruby-comment cmt"># Render the source file with the temporary binding.</span>
295:             <span class="ruby-constant">ERB</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">file</span>.<span class="ruby-identifier">read</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-value str">'-'</span>).<span class="ruby-identifier">result</span>(<span class="ruby-identifier">b</span>)
296:           <span class="ruby-keyword kw">end</span>
297:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>